package com.evaluation.utils;

import com.evaluation.dto.PJDTO;
import com.evaluation.entity.EvaluateEntity;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;

import java.io.FileOutputStream;
import java.io.IOException;
import java.util.List;

public class MakeExcelUtil {

    public static String createExcel(List<PJDTO> pjdtos){

        HSSFWorkbook workbook=new HSSFWorkbook();

        HSSFSheet sheet= workbook.createSheet("分数表1");
        HSSFRow row= sheet.createRow(0);
        HSSFCell cell= row.createCell(0);
        cell.setCellValue("教师");

        cell= row.createCell(1);
        cell.setCellValue("课程名称");

        cell= row.createCell(2);
        cell.setCellValue("平均分");

        cell= row.createCell(3);
        cell.setCellValue("课程时间");

       /* cell= row.createCell(4);
        cell.setCellValue("分数");

        cell= row.createCell(5);
        cell.setCellValue("时间");*/

        for (int i=0;i<pjdtos.size();i++){
            HSSFRow row1= sheet.createRow(i+1);
            PJDTO pjdto= pjdtos.get(i);
            row1.createCell(0).setCellValue(pjdto.getTeacherName());
            row1.createCell(1).setCellValue(pjdto.getCourseName());
            row1.createCell(2).setCellValue(pjdto.getZongfen());
            row1.createCell(3).setCellValue(pjdto.getShijian());
           /* row1.createCell(4).setCellValue(pjdto.getZongfen());
            row1.createCell(5).setCellValue(pjdto.getShijian());*/
        }
        try{
            FileOutputStream fos=new FileOutputStream("D:\\fen1.xls");
            workbook.write(fos);
            fos.close();
            return "写入成功";
        }catch (IOException e){
            e.printStackTrace();
            return "写入失败";

        }



    }


}
